<template>
	<view class="diamond_records">
		<view v-for="item in list" :key="item.id" class="diamond_records__item">
			<view class="diamond_records__left">
				<veiw>{{ item.remark }}</veiw>
				<veiw class="diamond_records__time">{{ item.created_at }}</veiw>
			</view>
			<text class="diamond_records__amount" v-if="Number(item.gold) > 0">+{{ item.gold }}</text>
			<text class="diamond_records__amount" v-else>{{ item.gold }}</text>
		</view>
		<view class="tip_records__loading">
			<u-loadmore :status="status" />
		</view>
	</view>
</template>

<script>
	import {accountLog} from '@/common/api.js'
	
	export default {
		data() {
			return {
				list: [],
				page: 1,
				finished: false,
				status: 'loadmore'
			};
		},
		onShow() {
			this.getAccountLog()
		},
		onReachBottom() {
			if (this.finished) return
			this.page++
			this.getAccountLog()
		},
		methods: {
			getAccountLog() {
				this.status = 'loading'
				accountLog({page: this.page, type: 'GOLD'}).then(({data}) => {
					if (data.current_page === 1) {
						this.list = data.list
					} else {
						this.list = this.list.concat(data.list)
					}
					this.finished = data.current_page >= data.total_page
					this.status = this.finished ? 'nomore' : 'loading'
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.diamond_records__left {
		display: flex;
		flex-direction: column;
	}
	.diamond_records__time {
		color: #999;
		margin-top: 10rpx;
		font-size: 24rpx;
	}
	.diamond_records__amount {
		font-size: 32rpx;
		color: #0862EC;
	}
	.diamond_records__item {
		background-color: #fff;
		padding: 20rpx;
		margin: 20rpx 20rpx 0;
		border-radius: 12rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
	.tip_records__loading {
		padding-top: 40rpx;
		text-align: center;
	}
</style>
